package com.zcx.qshop.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/8/24 0024.
 */
@HttpInlet(Conn.INTEL_JSON_SCHOOL)
public class JsonSchoolAsyGet extends QSAsyGet<JsonSchoolAsyGet.Info> {

    public String code;

    public JsonSchoolAsyGet(String code, AsyCallBack<Info> asyCallBack) {

        super(asyCallBack);

        this.code = code;

    }

    @Override
    public Info parser(JSONObject object) {

        if(object.optString("message").equals("1")){

            Info info = new Info();

            JSONArray array = object.optJSONArray("schoollist");

            for (int i = 0 ; i < array.length() ; i++){

                Info.School school = new Info.School();

                JSONObject o = array.optJSONObject(i);

                school.sid = o.optString("sid");

                school.name = o.optString("name");

                info.schools.add(school);

            }

            return info;

        }

        return null;

    }

    public static class Info{

        public List<School> schools = new ArrayList<>();

        public static class School{

            public String sid, name;

        }

    }

}
